invokeRemoteMethod("clientSideRequestBuyAllMoviesStarringTalent",
new Object[] {talent});
}
The method begins with "clientSideRequest"; this is not accidental. The EODistributionContext object on the server-side EODistribution layer will reject a remote invocation unless it has this prefix or its delegate implements the proper delegation methods (see the reference documentation for EODistributionContext or EODistributedObjectStore for more information).
The following is the invoked method, which is implemented in the server's Studio.java:
talentMovies = talent.moviesStarredIn();
count = talentMovies.count();
for (i = 0; i < count; i++) {
movie =
(EOEnterpriseObject)(talentMovies.objectAtIndex(i));
if (!(movies().containsObject(movie))) {
studio =
(EOEnterpriseObject)(movie.valueForKey("studio"));
if (studio != null)
studio.
removeObjectFromBothSidesOfRelationshipWithKey
(movie,"movies");
addObjectToBothSidesOfRelationshipWithKey
(movie,"movies");
}
}
}
This method invokes the moviesStarredIn method:
moviesStarredIn = new NSMutableArray();
movies = (NSArray)(roles().valueForKey("movie"));
count = movies.count();
for (i = 0; i < count; i++) {
movie = (EOEnterpriseObject)(movies.objectAtIndex(i));
if (!(moviesStarredIn.containsObject(movie))) {
moviesStarredIn.addObject(movie);
}
}
return moviesStarredIn;
}
You can associate the buyAllMoviesStarringTalent method with a user interface control. But first you need to add to your user interface a table view that lists all actors (talent).
Drag the Talent entity from your model into the nib file window in Interface Builder.
Drag a table view from the Palette onto your window.
Control-drag from each table view column to the Talent EODisplayGroup.
Using the value aspect of the EOColumnAssoc, connect the table view columns to the firstName and lastName class keys, respectively.
Drag a button into the window.
Place it below the Revenue field.
Give it the title "Buy Movies Starring Selected Talent".
Display the Attributes view of the Inspector for the Studio EODisplayGroup.
In the text field type the name of the method ( buyAllMoviesStarringTalent ) you want to use in an association.
Control-drag from the "Buy Movies Starring Selected Talent" button to the Studio EODisplayGroup.
In the Connections Inspector, choose EOActionAssociation from the pop-up list at the top of the left column.
Select action in the left column, and the method you want to connect to ( buyAllMoviesStarringTalent ) in the right column.
Control-drag from the "Buy Movies Starring Selected Talent" button to the Talent EODisplayGroup.
In the Inspector, select argument in the left column. The argument aspect takes the destination of the connection (Talent) as an argument, which will be supplied to the buyAllMoviesStarringTalent method.